<?php
class OrderSearchAction extends CommonAction {
	
	/**
	 * 查询(non-PHPdoc)
	 * @see CommonAction::read()
	 */
	public function readOrder() {
		$map = " and 1=1 ";
		
		if(!empty($_POST['DD_KHMC'])) {
			//$map = $map." and dd.DD_KHMC = '".$_POST['DD_KHMC']."'";
			$map = $map ." and (dd.DD_KHPY like '%".$_POST['DD_KHMC']."%' or dd.DD_KHMC like '%".$_POST['DD_KHMC']."%')";
		}
		if(!empty($_POST['DD_ZD'])) {
			$map = $map." and dd.DD_ZD = '".$_POST['DD_ZD']."'";
		}
		if(!empty($_POST['DD_DDZT'])) {
			$map = $map." and dd.DD_DDZT = '".$_POST['DD_DDZT']."'";
		}
		if(!empty($_POST['DD_FP'])) {
			$map = $map." and dd.DD_FP = '".$_POST['DD_FP']."'";
		}
		if(!empty($_POST['DD_PPMC'])) {
			$map = $map ." and dd.DD_PPMC like '%".$_POST['DD_PPMC']."%'";
		}
		
		if((!empty($_POST['DD_CJSJ_BEGIN']))&&(!empty($_POST['DD_CJSJ_END']))) {		
			$map = $map." and dd.DD_CJSJ between '".$_POST['DD_CJSJ_BEGIN']."' and '".$_POST['DD_CJSJ_END']."'";
		}
			
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		
		$Order = M ( "Order" );		
		$arrNum = $Order->query("select count(*) as num from smis_order dd where 1=1 " . $map);
		$row = $arrNum[0]['num'];
		$total = $row;		

		$Orders = array ();
		$Orders = $Order->table('smis_order dd, smis_dictionary_list dictionary,smis_dictionary_list dictionary1,smis_dictionary_list dictionary2')
						->where('dd.DD_ZFFS = dictionary.ITEM_KEY and dd.DD_DDZT = dictionary1.ITEM_KEY and dd.DD_ZD = dictionary2.ITEM_KEY' .$map)
						->field('dd.*,dictionary.ITEM_VALUE as ZFFS,dictionary1.ITEM_VALUE as DDZT,dictionary2.ITEM_VALUE as ZD')
						->order('dd.DD_CJSJ desc' )
		                ->page($pagenum,$rowsnum)->select();
		
		$resultJson = json_encode($Orders);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
		
	}
	
	/**获取课程列表信息
	 * 查询(non-PHPdoc)
	 * @see CommonAction::read() 
	 * */
	public function getCourseList() {
		
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$course = D ( "Course" );
		$map = " and course.status ='1' " ;
		
		$xqid =  $_SESSION['XqFilterString'] ;//获取用户当前拥有校区权限
		if(!empty($xqid)){
			$map = $map." and course.KC_XQ in (".$xqid.") ";
		}
		
		$arrNum = $course->query("select count(*) as num from smis_course dd where 1=1 " . $map);
		$row = $arrNum[0]['num'];
		$total = $row;
		
		$courseList = array ();
		$courseList = $course->table('smis_course course, smis_dictionary_list dictionary')
		->where('course.KC_KMBH = dictionary.ITEM_KEY'.$map)
		->field('course.*,dictionary.ITEM_VALUE as KMMC')
		->order('course.id desc' )
		->page($pagenum,$rowsnum)->select();
		
		$resultJson = json_encode($courseList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}
	
	
	/**
	 * 获取报名单流水明细
	 */
	public function  readOrderDetails(){
		if(!empty($_POST['LS_DDBH'])) {
			$map['LS_DDBH'] = $_POST['LS_DDBH'];
			$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
			$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
			$OrderDetails = M ( "OrderList" );
			
			$total = $OrderDetails->where($map)->count (); // 计算总数
			import("ORG.Util.Page");// 导入分页类
			$Orders = array ();
			$Orders = $OrderDetails->where($map)->limit ( ($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
			$resultJson = json_encode($Orders);
			if($resultJson == "null"){//如果查询结果返回为null
				$resultJson = "[]";
			}
		}else {
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}
		
	
	/**
	 * 获取学生列表
	 */
	public function studentList() {
		$map =  array ();
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$Student = M ( "Student" );
		
		$xqid =  $_SESSION['XqFilterString'] ;//获取用户当前拥有校区权限
		if(!empty($xqid)){
			$xqid = str_replace("'","",$xqid);
			$map['XS_XQ']  = array('in',$xqid);
		}
		
		if(!empty($_POST['KHMC'])) {
			$KCMC = $_POST['KHMC'];
			$keyword = "%". $KCMC ."%";
			$where['_logic'] = 'or';
			$where['XS_XM'] = array('like',$keyword );
			$where['XS_PY'] = array('like',$keyword );
			$where['XS_XH'] = array('like',$keyword );
			$map['_complex'] = $where;
		}
		
		$map['XS_ZT'] = 'xszt1'; //表明活跃的学生
		
		$total = $Student->where($map)->count (); // 计算总数
		//$list = $db -> field( "$table.art_id,$table.art_title,$table.art_content,$table.art_description,$table2.cate_id,$table2.cate_name" ) ->
		$studentList = array ();
		$studentList = $Student->where($map)->limit ( ($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
		$resultJson = json_encode($studentList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}
		
	/**
	 * 获取优惠劵列表
	 */
	public function couponList() {
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$Coupon = M ( "Coupon" );
		$fix = C( "DB_PREFIX" );				
		import("ORG.Util.Page");// 导入分页类	
			
		$nowDate = date("Y-m-d");	
		$map['status'] = '1';
		$map['YHK_KSSJ']=array('elt',$nowDate);
		$map['YHK_JSSJ']=array('egt',$nowDate);		
		
		$total = $Coupon->where($map)->count (); // 计算总数
		$couponList = array ();
		$couponList = $Coupon->where($map)->limit ( ($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
		$resultJson = json_encode($couponList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}	
	
}
?>